//
//  KeyFrameAnimationViewController.m
//  30303Animations
//
//  Created by student on 16/3/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "KeyFrameAnimationViewController.h"

@interface KeyFrameAnimationViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *plane;

@end

@implementation KeyFrameAnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //关键帧
    
    //1.沿着关键路径移动
    CGMutablePathRef planePath=CGPathCreateMutable();
    CGPathMoveToPoint(planePath, NULL, 160.0, 100.0);
    CGPathAddLineToPoint(planePath, NULL, 100.0, 280.0);
    CGPathAddLineToPoint(planePath, NULL, 260.0, 170.0);
    CGPathAddLineToPoint(planePath, NULL, 60.0, 170.0);
    CGPathAddLineToPoint(planePath, NULL, 220.0, 280.0);
    CGPathCloseSubpath(planePath);
    
    CAKeyframeAnimation *anim=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    [anim setPath:planePath];
    anim.duration=3;
    [self.plane.layer addAnimation:anim forKey:nil];
    
    //释放
    CFRelease(planePath);
    planePath=nil;
    
    //设定关键时间点，及关键时间对应的值
    CAKeyframeAnimation *anim2=[CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    anim2.duration = 3;
    anim2.keyTimes = @[@0.2,@0.4,@0.6,@0.8,@1];//时间点 0~1
    anim2.values = @[@0.25,@1,@0.5,@1,@2];// 对应时间点的值是多少
    [self.plane.layer addAnimation:anim2 forKey:nil];

}
@end
